<?php

require_once PATH_NAME . '/utilities/sessions.php';
class HTML{
	public function __construct(){}
	
	public function getLanguage(){		
		$lang = sessions::getSessionByName();
		if (file_exists('language/default_'.$lang.'.php')){			
			require_once 'language/default_'.$lang.'.php';
		}else{
			require_once 'language/default_en.php';
		}
	}
	
	public function topHTML( $title = '' ){
	?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
		<html>
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title><?php echo $title?></title>
		<LINK REL=StyleSheet HREF="<?php echo WROOT?>views/css/css.css" TYPE="text/css" MEDIA=screen>				
		<script type="text/javascript" src="<?php echo WROOT?>views/js/query.min.js" language="javascript"></script>
		<script type="text/javascript" src="<?php echo WROOT?>views/js/liveclock.js" language="javascript"></script>
		<script type="text/javascript" src="<?php echo WROOT?>views/js/jquery-1.5.1.min.js" language="javascript"></script>
        <script type="text/javascript" src="<?php echo WROOT?>views/js/camlot.js" language="javascript"></script>                
		</head>
	<?php 		
	}
	
	public function wrapperHeaderHTML(){
	?>
		<body>	
		<center>
			<div id="wrapper">
	<?php 	
	}
	public function wrapperFooterHTML(){
	?>		
			</div>		
		</center>
        </body>
		</html>		
	<?php 	
	}
	public function footHTML(){
	?>
    	</body>
		</html>
    <?php	
	}
	public function headerHTML( $userName = '' ){		
		HTML::getLanguage();
		?>		
		<script>
			$(function (){
				show_clock();
			});
		</script>
		<div class="header">
			<div class="float_left header_left"><?php echo NEW_WORLD_LOTTORY ?></div>
			<div class="float_right header_right">
			<?php 
				$date = Date('d/m/Y');
				echo "<div>".$date."</div>";
				echo "<div id='LiveClockIE'></div>";
				echo "<div>".$userName."</div>";
			?>
			</div>
			<div class="clear">&nbsp;</div>
		</div>
		<?php 
	}
	public function pagination( $numrows = 0, $nbPage = 1, $sOrder = 'ASC', $url = '', $rowsPerPage = 10 )
	{
		$pageNum = 1;
		
		if(!empty($nbPage) && $nbPage > 1){
			$pageNum = $nbPage;
		}
		// counting the offset
		$offset = ($pageNum - 1) * $rowsPerPage;
		
		//Get all tyep materiel
		$order = "ASC";
		if ( $sOrder == 'DESC' )
		{
			$order = $sOrder;	
		}elseif( $sOrder == 'ASC' )
		{
			$order = $sOrder;
		}		
		
		$maxPage = ceil($numrows/$rowsPerPage);
		
		$nav  = '';

		for($page = 1; $page <= $maxPage; $page++)
		{
		   if ($page == $pageNum)
		   {
			  $nav .= "<strong class=paging_active>".$page."</strong>&nbsp;"; // no need to create a link to current page
		   }else
		   {
			  $nav .= "<a href=\"#\" class=\"paging\" \">$page</a>&nbsp;";
		   }
		}	
		
		if ($pageNum >= 1)
		{				
			$page  = $pageNum - 1;
			if ($pageNum != 1){
				$prev  = " <a href=\"#\" class=\"paging\" \">&lt;&lt;</a> ";          
				$first = " <a href=\"#\" class=\"paging\" \">First</a> ";
			}else{
				$first = "<strong class=paging_active>First</strong>&nbsp;<strong class=paging_active>&lt;&lt;</strong>&nbsp;";
				$prev = "";
			}
		}            
		
		if ($pageNum <= $maxPage)
		{
			$page = $pageNum + 1;
			if ($pageNum != $maxPage){               	
				$next = "<a href=\"#\" class=\"paging\" \">&gt;&gt;</a>";
				$last = "&nbsp;<a href=\"#\" class=\"paging\" \">Last</a>";
			}else{
				$last = "<strong class=paging_active>&gt;&gt;</strong>&nbsp;<strong class=paging_active>Last</strong>";	
				$next = "";
			}
		}
		if ($numrows > $rowsPerPage)
		{
			return  "<div style='float: left'>Total : <span id='totalList'>".$numrows."</span></div><div style='float: right'>" .$first . $prev . $nav . $next . $last . "</div><div style='clear: both'>&nbsp;</div>"; 
		}else
		{
			return "";
		}
	}
	public function getCalendar( $lang = 'en', $name = '', $value = '', $nb = false){
	?>
    	<?php
		if ($nb){
		?>
			<script src="<?php echo WROOT?>views/js/calendar/jscal2.js"></script>
            <script src="<?php echo WROOT?>views/js/calendar/lang/<?php echo $lang?>.js"></script>
            <link rel="stylesheet" type="text/css" href="<?php echo WROOT?>views/js/calendar/css/jscal2.css" />
            <link rel="stylesheet" type="text/css" href="<?php echo WROOT?>views/js/calendar/css/border-radius.css" />
            <link rel="stylesheet" type="text/css" href="<?php echo WROOT?>views/js/calendar/css/steel/steel.css" />  
        <?php
    	}
		?>
    	<input id="<?php echo $name?>" name="<?php echo $name?>" value="<?php echo @$value?>" readonly="readonly" /><button id='<?php echo $name?>btn'>...</button>		
        <script type="text/javascript">//<![CDATA[
		//$(function(){
			 Calendar.setup({
				inputField : "<?php echo $name?>",
				trigger    : "<?php echo $name?>btn",
				onSelect   : function() { this.hide() },
				showTime   : 12,
				//dateFormat : "%Y-%m-%d %I:%M %p"
				dateFormat : "%Y-%m-%d"
			  });
		//});
		//]]></script>
       
    <?php	
	}
	public function selectBox( $name = '', $lists = NULL, $default = false, $id = 0, $muilt = false ,$javaScript = '' ){		
		$select  = "<select name=".$name." id=".$name." size='1' ".$javaScript.">";
		$select .= ($default) ? "<option value=''></option>":"";		
		foreach($lists as $list){	
			$seleced = ($list->id == $id) ? "selected='selected'" : "";		
			$select .= "<option " .$seleced. " value=". $list->id .">". $list->name ."</option>";
		}
		$select .= "</select>";
		return $select;
	}
}
?>